package com.fqgj.xjd.user.dao.impl;

import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.xjd.user.dao.UserAuthPanDao;
import com.fqgj.xjd.user.entity.UserAuthPanEntity;
import com.fqgj.xjd.user.entity.business.UserPanStatisticsEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: liuming
 * Date: 2018-08-17
 * Time: 16:26:12.280
 */

@Repository
public class UserAuthPanDaoImpl extends AbstractBaseMapper<UserAuthPanEntity> implements UserAuthPanDao {

    @Override
    public UserAuthPanEntity selectUserPanByUserCode(String userCode) {
        return getSqlSession().selectOne(getStatement("selectUserPanByUserCode"), userCode);
    }

    /**
     * 获取用户PanCard
     */
    @Override
    public UserAuthPanEntity selectUserPanByPanNo(String cardNo) {
        return getSqlSession().selectOne(getStatement("selectUserPanByPanNo"), cardNo);
    }

    @Override
    public List<UserAuthPanEntity> selectUserPansByPanNo(String cardNo) {
        return getSqlSession().selectList(getStatement("selectUserPansByPanNo"), cardNo);
    }

    @Override
    public List<UserAuthPanEntity> selectUserPansByMD5PanNo(String md5CardNo) {
        return getSqlSession().selectList(getStatement("selectUserPansByMD5PanNo"), md5CardNo);
    }

    @Override
    public void updatePanStatusAndUrl(UserAuthPanEntity userAuthPanEntity) {
        Map<String, String> params = new HashMap<>();
        params.put("userCode", userAuthPanEntity.getUserCode());
        params.put("panStatus", userAuthPanEntity.getPanStatus());
        params.put("cardUrl", userAuthPanEntity.getCardUrl());
        getSqlSession().update(getStatement("updatePanStatusAndUrl"), params);
    }

    /**
     * pancard 调用次数统计
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @Override
    public List<UserPanStatisticsEntity> selectUserPanStatistics(Date startDate, Date endDate) {
        Map<String, Object> params = new HashMap<>();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        return getSqlSession().selectList(getStatement("selectUserPanStatistics"), params);
    }

    @Override
    public List<UserAuthPanEntity> selectListByPage(Page page, Date endDate) {
        Map<String, Object> params = new HashMap<>();
        params.put("page", page);
        params.put("endDate", endDate);
        return getSqlSession().selectList(getStatement("selectListByPage"), params);
    }
}